package com.magicsoft.app.adapter;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.boyuan.huijiaoyu.R;
import com.magicsoft.app.entity.AuthorizationHistoryListResp;
import com.magicsoft.app.helper.DateUtils;
import com.magicsoft.app.helper.StringUtils;

public class AuthorizationHistoryListAdapter extends
		CTHAdapter<AuthorizationHistoryListResp> {
	private boolean flag;// true为申请界面反之授权界面

	public AuthorizationHistoryListAdapter(Context context, Boolean flag,
			List<AuthorizationHistoryListResp> data) {
		super(context, data);

		this.flag = flag;
	}

	@Override
	public int getCount() {

		return data.size();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		HolderViewStatic viewContent = new HolderViewStatic();

		AuthorizationHistoryListResp authorizationHistoryListResp = data
				.get(position);

		if (convertView == null) {

			convertView = mInflater.inflate(
					R.layout.authorization_history_list_item, null);

			viewContent.tv_time = (TextView) convertView
					.findViewById(R.id.tv_time);
			viewContent.tv_status = (TextView) convertView
					.findViewById(R.id.tv_status);

			convertView.setTag(viewContent);

		} else {
			viewContent = (HolderViewStatic) convertView.getTag();
		}

		if (authorizationHistoryListResp != null) {

			viewContent.tv_time.setText(DateUtils
					.phpToTimeString(authorizationHistoryListResp
							.getModifiedtime()));
			String auTypeString = "";

			if (flag) {

				String auType = authorizationHistoryListResp.getStatus();
				if (StringUtils.isNotEmpty(auType)) {
					if ("0".equals(auType)) {
						auTypeString = "未批复";
					} else if ("1".equals(auType)) {
						auTypeString = "通过";
					} else if ("2".equals(auType)) {
						auTypeString = "拒绝";
					}
				} else {
					// 授权类型
					String type = authorizationHistoryListResp.getUsertype();

					if ("1".equals(type)) {
						auTypeString = "永久";
					} else if ("2".equals(type)) {
						auTypeString = "7天";
					} else if ("3".equals(type)) {
						auTypeString = "1天";
					} else if ("4".equals(type)) {
						auTypeString = "2小时";
					} else if ("5".equals(type)) {
						auTypeString = "1年";
					} else if ("0".equals(type)) {
						auTypeString = "未处理";
					}

				}

			} else {
				// 授权类型
				String auType = authorizationHistoryListResp.getUsertype();

				if ("1".equals(auType)) {
					auTypeString = "永久";
				} else if ("2".equals(auType)) {
					auTypeString = "7天";
				} else if ("3".equals(auType)) {
					auTypeString = "1天";
				} else if ("4".equals(auType)) {
					auTypeString = "2小时";
				} else if ("5".equals(auType)) {
					auTypeString = "1年";
				}

			}
			viewContent.tv_status.setText(auTypeString);
		}

		return convertView;

	}

	static class HolderViewStatic {
		TextView tv_time;
		TextView tv_status;
	}
}
